import 'dart:io';

import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:finance_app/src/common/config.dart';

/// 登录
class HttpLoginService {
  /// 查询电话号码
  static Future<Response> loginCheck(
      String countryCode, String phoneNumber, String otp) {
    return BaseConfig.httpBase.postJson('/api/login/check', {
      'country_code': countryCode,
      'phone_number': phoneNumber,
      'otp': otp,
    });
  }

  /// 获取注册OTP
  static Future<Response> loginOtp(String countryCode, String phoneNumber) {
    return BaseConfig.httpBase.postJson('/api/otp', {
      "country_code": countryCode,
      'phone_number': '$phoneNumber',
      'type': 'register',
    });
  }

  /// otp检测
  static Future<Response> otpCheckForget(
      String countryCode, String phoneNumber, String otp) {
    return BaseConfig.httpBase.postJson('/api/otp/check', {
      "country_code": countryCode,
      'phone_number': '$phoneNumber',
      'otp': '$otp',
      'type': 'reset'
    });
  }

  static Future<Response> otpCheckRegister(
      String countryCode, String phoneNumber, String otp) {
    return BaseConfig.httpBase.postJson('/api/otp/check', {
      "country_code": countryCode,
      'phone_number': '$phoneNumber',
      'otp': '$otp',
      'type': 'register',
    });
  }

  /// 登录/注册
  static Future<Response> login(String countryCode, String phoneNumber,
      [int otp, String password]) {
    return BaseConfig.httpBase.postJson('/api/login', {
      'country_code': countryCode,
      'phone_number': phoneNumber,
      'otp': otp,
      'player_id': Config.pushKey,
      'password': password,
      'device': Platform.isIOS ? 'ios' : 'android'
    });
  }

  /// 注册
  static Future<Response> register(String countryCode, String phoneNumber,
      [String otp]) {
    return BaseConfig.httpBase.postJson('/api/register', {
      'country_code': countryCode,
      'phone_number': phoneNumber,
      'otp': otp,
      'player_id': Config.pushKey,
      'device': Platform.isIOS ? 'ios' : 'android'
    });
  }

  /// demo
  static Future<Response> requestDemo(
      String name, String email, String countryCode, String phoneNumber) {
    return BaseConfig.httpBase.postJson('/api/register/demo', {
      'name': name,
      'email': email,
      'country_code': countryCode,
      'phone_number': phoneNumber,
    });
  }

  /// 获取重置OTP
  static Future<Response> resetOtp(String countryCode, String phoneNumber) {
    return BaseConfig.httpBase.postJson('/api/otp', {
      "country_code": countryCode,
      'phone_number': '$phoneNumber',
      'type': 'reset',
    });
  }

  /// 重置
  static Future<Response> resetPhoneNumber(
      String countryCode, String phoneNumber, String password, String otp) {
    return BaseConfig.httpBase.postJson('/api/reset', {
      'phone_number': phoneNumber,
      'password': password,
      'country_code': countryCode,
      'otp': otp,
    });
  }

  /// 更改手机号获取OTP
  static Future<Response> changeOtp(String countryCode, String phoneNumber) {
    return BaseConfig.httpBase.postJson('/api/otp', {
      "country_code": countryCode,
      'phone_number': '$phoneNumber',
      'type': 'change',
    });
  }

  /// 注册
  static Future<Response> registerByEmail(String email, [String otp]) {
    return BaseConfig.httpBase.postJson('/api/email_register', {
      'email': email,
      'otp': otp,
      'device': Platform.isIOS ? 'ios' : 'android',
      'player_id': Config.pushKey
    });
  }

  static Future<Response> otpCheckEmailRegister(String email, String otp) {
    return BaseConfig.httpBase.postJson('/api/email_otp/check', {
      "email": email,
      'otp': '$otp',
      'type': 'register',
    });
  }

  /// 登录/注册
  static Future<Response> loginByEmail(String email,
      [int otp, String password]) {
    return BaseConfig.httpBase.postJson('/api/email_login', {
      'email': email,
      'otp': otp,
      'player_id': Config.pushKey,
      'password': password,
      'device': Platform.isIOS ? 'ios' : 'android'
    });
  }

  /// 获取注册email OTP
  static Future<Response> loginEmailOtp(String email) {
    return BaseConfig.httpBase.postJson('/api/email_otp', {
      'email': '$email',
      'type': 'register',
    });
  }

  /// 查询email OTP
  static Future<Response> loginEmailCheck(String email, String otp) {
    return BaseConfig.httpBase.postJson('/api/email_otp', {
      'email': '$email',
      'otp': '$otp',
    });
  }

  /// 获取重置email OTP
  static Future<Response> resetOtpByEmail(String email) {
    return BaseConfig.httpBase.postJson('/api/email_otp', {
      "email": email,
      'type': 'reset',
    });
  }

  /// 更改email获取OTP
  static Future<Response> changeEmailOtp(String email) {
    return BaseConfig.httpBase.postJson('/api/email_otp', {
      "email": email,
      'type': 'change',
    });
  }

  /// otp email 检测
  static Future<Response> otpEmailCheckForget(String email, String otp) {
    return BaseConfig.httpBase.postJson('/api/email_otp/check',
        {"email": email, 'otp': '$otp', 'type': 'reset'});
  }

  /// 重置email
  static Future<Response> resetEmail(
      String email, String password, String otp) {
    return BaseConfig.httpBase.postJson('/api/email_reset', {
      'email': email,
      'password': password,
      'otp': otp,
    });
  }
}
